﻿<UserControl x:Class="SQLDeploymentBuilder.UI.Controls.Connections.ConnectionList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:SQLDeploymentBuilder.UI.Converters"
             xmlns:connections="clr-namespace:SQLDeployAnything.Data.Environment;assembly=SQLDeployAnything.Data"
             xmlns:editors="clr-namespace:SQLDeploymentBuilder.UI.Controls.Connections.Editors"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Style x:Key ="hcs" TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
        </Style>
        <converters:IsNullConverter x:Key="IsNullConverter"/>
    </UserControl.Resources>
    <Grid>

        <ListView Name="lsv_connections"
              IsHitTestVisible="True"
              IsTextSearchEnabled="True"
              SelectionMode="Single"
              >

            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Style.Triggers>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter Property="IsSelected" Value="True"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListView.ItemContainerStyle>

            <ListView.ContextMenu>
                <ContextMenu>
                    <!--
                    <ContextMenu.ItemContainerStyle>
                        <Style TargetType="MenuItem">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Converter={StaticResource IsNullConverter},NotifyOnSourceUpdated=True}" >
                                    <Setter Property="IsEnabled" Value="{Binding Converter={StaticResource IsNullConverter}, NotifyOnSourceUpdated=True}"/>    
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ContextMenu.ItemContainerStyle>
                    -->
                    <MenuItem Name="AddConnection" Header="Add Connection" 
                              IsEnabled="{Binding Converter={StaticResource IsNullConverter}}"
                              Command="{Binding AddConnection}">

                    </MenuItem>
                    <MenuItem Header="Delete Connection"
                              IsEnabled="{Binding Converter={StaticResource IsNullConverter}}"
                              Command="{Binding RemoveItem}"
                              CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}" />
                </ContextMenu>
            </ListView.ContextMenu>

            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" Width="auto" DisplayMemberBinding="{Binding Name}" HeaderContainerStyle="{StaticResource hcs}"/>
                    <GridViewColumn Header="Details" Width="auto" DisplayMemberBinding="{Binding ConnectionDetails}" HeaderContainerStyle="{StaticResource hcs}"/>
                </GridView>
            </ListView.View>
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Image Grid.Column="0" Grid.Row="0"
                                   />
                                <!--Add Image here later-->
                                <TextBlock 
                                Grid.Column="1" Grid.Row="0"
                                FontWeight="Bold" FontSize="14" Text="{Binding ConnectionTypeHeading}"/>
                            </Grid>

                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListView.GroupStyle>
            <connections:Connection ConnectionName="TestCon1"/>



        </ListView>

        <editors:AddTypeBox x:Name="AddTypeOfBox" 
                            DataContext="{Binding}"
                            Visibility="Collapsed"/>
    </Grid>


</UserControl>
